package com.pachong.android.frameworkbase.dialog;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;

import com.pachong.android.frameworkbase.R;
import com.pachong.android.frameworkbase.dialog.base.CenterDialogFragment;
import com.pachong.android.frameworkbase.utils.SceneAnimation;


/**
 * Progress Fragment
 *
 * @Author: PengWeiwei
 * @E-mail: pengveivei@sina.cn
 * @CreateDate: 2016-07-30
 * @Version: 1.0.0
 */
@SuppressLint("ValidFragment")
public class ProgressFragment extends CenterDialogFragment {
    AnimationDrawable mAnimation;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_progress, null);
        ImageView pbBase = (ImageView)view.findViewById(R.id.pb_base);
        int[] mFrameRes =new int[]{R.drawable.loading_01,
                R.drawable.loading_02,
                R.drawable.loading_03,
                R.drawable.loading_04,
                R.drawable.loading_05,
                R.drawable.loading_06,
                R.drawable.loading_07,
                R.drawable.loading_08,
                R.drawable.loading_09,
                R.drawable.loading_10,
                R.drawable.loading_11,
                R.drawable.loading_12,
                R.drawable.loading_13,
                R.drawable.loading_14,
                R.drawable.loading_15,
                R.drawable.loading_16,
                R.drawable.loading_17,
                R.drawable.loading_18,
                R.drawable.loading_19,
                R.drawable.loading_20,
                R.drawable.loading_21,
                R.drawable.loading_22,
                R.drawable.loading_23,
                R.drawable.loading_24,
                R.drawable.loading_25,
                R.drawable.loading_26,
                R.drawable.loading_27,
                R.drawable.loading_28,
                R.drawable.loading_29,
                R.drawable.loading_30,
                R.drawable.loading_31,
                R.drawable.loading_32,
                R.drawable.loading_33,
                R.drawable.loading_34
        };
        new SceneAnimation(pbBase,mFrameRes,60);
//        if(mAnimation==null){
//        mAnimation = new AnimationDrawable();
//        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_01),60);
////        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_02),60);
//        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_03),60);
////        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_04),60);
//        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_05),60);
////        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_06),60);
//        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_07),60);
////        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_08),60);
//        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_09),60);
////        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_10),60);
//        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_11),60);
////        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_12),60);
//        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_13),60);
////        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_14),60);
//        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_15),60);
////        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_16),60);
//        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_17),60);
////        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_18),60);
//        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_19),60);
////        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_20),60);
//        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_21),60);
////        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_22),60);
//        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_23),60);
////        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_24),60);
//        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_25),60);
////        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_26),60);
//        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_27),60);
////        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_28),60);
//        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_29),60);
////        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_30),60);
//        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_31),60);
////        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_32),60);
//        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_33),60);
////        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_34),60);
//        mAnimation.addFrame(getContext().getResources().getDrawable(R.drawable.loading_35),60);
//            pbBase.setBackground(mAnimation);
//            mAnimation.setOneShot(false);
//            mAnimation.start();
//        }else{
//            pbBase.setBackground(mAnimation);
//            mAnimation.setOneShot(false);
//            mAnimation.start();
//        }

//        if (Build.VERSION.SDK_INT > 22) {//android 6.0替换clip的加载动画
//            Log.e("11111111","2222222");
//            pbBase.setIndeterminate(true);
//
//            final Drawable drawable = mContext.getApplicationContext().getResources().getDrawable(R.drawable.progress_loading);
//            pbBase.setIndeterminateDrawable(drawable);
//        }
        return view;
    }


    @SuppressLint("ValidFragment")
    public ProgressFragment() {
        setHasMargin(true);
    }


}
